#if(QT_VERSION_MAJOR EQUAL 6)
#    qt_add_executable(App WIN32
#        main.cpp
#        zeal.qrc
#        ${App_RESOURCES}
#    )
#else()
#    add_executable(App WIN32
#        main.cpp
#        zeal.qrc
#        ${App_RESOURCES}
#    )
#endif()

#target_link_libraries(App PRIVATE Core Util Qt${QT_VERSION_MAJOR}::Widgets)

#set_target_properties(App PROPERTIES
#    OUTPUT_NAME ${_project_output_name}
#    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
#)

find_package(duc-base REQUIRED)
find_package(duc-common REQUIRED)
find_package(duc-framework REQUIRED)
find_package(duc-services REQUIRED)
find_package(Dtk COMPONENTS Widget REQUIRED)
set(QtFindModules Core Gui Widgets Concurrent WebEngineWidgets)
foreach(QtModule ${QtFindModules})
    find_package(Qt5 COMPONENTS ${QtModule} REQUIRED)
    # include qt module private include directors
    include_directories(${Qt5${QtModule}_PRIVATE_INCLUDE_DIRS})
    # can use target_link_libraries(xxx ${QtUseModules})
    list(APPEND QtUseModules "Qt5::${QtModule}")
    message("QtModule found ${QtModule} OK!")
endforeach()

set(CXX_CPP
    demo.cpp
    main.cpp
    eventreceiver.cpp
    demo.json
    )

set(CXX_H
    demo.h
    eventreceiver.h
    )

add_library(${PROJECT_NAME}
    SHARED
    ${CXX_H}
    ${CXX_CPP}
    zeal.qrc
    )

project(Zeal
    VERSION 0.7.3
    DESCRIPTION "A simple documentation browser."
    HOMEPAGE_URL "https://zealdocs.org"
    LANGUAGES CXX
)
message(${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME}
    ${duc-framework_LIBRARIES} # plug-in framework, must be set
    ${duc-base_LIBRARIES}
    ${duc-common_LIBRARIES}
    ${duc-services_LIBRARIES}
    ${QtUseModules}
    ${PkgUserModules}
    ${DtkWidget_LIBRARIES}
    Core 
    Util
    )

#
# CPack configuration.
#
set(CPACK_GENERATOR "7Z;ZIP")

set(CPACK_VERBATIM_VARIABLES YES)

# Usage: cmake --build --preset <preset-name> --target package
# E.g. cmake --build build --preset ninja-multi-vcpkg-release --target package
set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
set(CPACK_PACKAGE_DESCRIPTION ${CMAKE_PROJECT_DESCRIPTION})
set(CPACK_PACKAGE_VENDOR ${PROJECT_COMPANY_NAME})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/src/app/resources/zeal.ico")

if(ZEAL_PORTABLE_BUILD)
    string(PREPEND _package_file_name_suffix "-portable")
endif()

set(CPACK_PACKAGE_FILE_NAME "${_project_output_name}-${ZEAL_VERSION_FULL}${_package_file_name_suffix}")

set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
set(CPACK_PACKAGE_LIBRARYS ${_project_output_name} ${CPACK_PACKAGE_NAME})
set(CPACK_CREATE_DESKTOP_LINKS ${_project_output_name} ${CPACK_PACKAGE_NAME})

# Allow CPack to do text to RTF conversion.
configure_file("${CMAKE_SOURCE_DIR}/COPYING" "${CMAKE_CURRENT_BINARY_DIR}/license.txt" COPYONLY)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_BINARY_DIR}/license.txt")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")

set(CPACK_PACKAGE_CHECKSUM SHA256)

# Set options for the source package.
# Usage: cmake --build <build> --target package_source
set(CPACK_SOURCE_GENERATOR "TGZ;TXZ;ZIP")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${_project_output_name}-${ZEAL_VERSION_FULL}")
set(CPACK_SOURCE_IGNORE_FILES
    # Directories.
    ".git/"
    ".github/"
    ".vscode/"
    "build/"
    # Files.
    ".editorconfig"
    ".gitattributes"
    ".gitignore"
)

include(CPack)

if(NOT PLUGIN_INSTALL_PATH)
    set(PLUGIN_INSTALL_PATH "/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/deepin-unioncode/plugins")
endif()

install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH})